//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_BASE_THREAD_H
#define _UX_BASE_THREAD_H

#include "IThread.h"

namespace Engine
{
namespace CoreSystems
{

	//
	// Base Thread
	//

	class _EXPORT_ CBaseThread : public CEngBaseObject, public IThread
	{
	protected:
		CCore				*	_pCore;

	private:
		TThread					_sThread;
		operations_queue_t		_aOpQueue;
		TCriticalSection		_sCSLockQueue;
		volatile bool			_bLooping : 1;
		
		static DThreadProc( _s_ThreadProc );

	protected:
		inline  bool _IsThreadExit(uint uTime);
		inline  void _ExitThread();
		inline  bool _IsLooping()	const	{ return _bLooping; }
		virtual uint _MainLoop();
		virtual void _OnStart();
		virtual void _OnEnter();
		virtual void _OnExit();
		virtual bool _Start(e_thread_priority::type ePriority, CCore *pCore);

	public:
		CBaseThread();
		~CBaseThread();

		virtual bool Push(IOperation *pOp, bool bHighPriority = false);
		virtual bool Pause();
		virtual bool Resume();
		virtual void Exit();
		virtual bool IsCurrent();
	};

//-------------------------------------------------------------------

}	// CoreSystems
}	// Engine

#endif	// _UX_BASE_THREAD_H